import { defineStore } from 'pinia'
import {userlogin} from '../api/login'
import {router} from '../router/index'
export const useUserStore = defineStore({
  id: 'user', // id必填，且需要唯一
  state: () => {
    return {
      xiaoFang_token: '',
      loginInfo:{},
    }
  },
  actions:{
      login(form ={password:'',username:''}){
      userlogin(form).then(res=>{
        if(res.code == '0000'){
          this.xiaoFang_token = res.data.result.token
          this.loginInfo =  res.data.result
          router.push('/home')
        }
      }).catch(err=>{
        console.log(err)
      })
    },
    getList(e){
      alert(e)
    }
  },
  persist: {
    enabled: true,
    strategies: [
      {
        key: 'xiaoFang_user',
        storage: localStorage,
      }
    ]
  }
})